Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Arrays. #2888

Merged
merged 51 commits into from
Oct 27, 2023
Merged

[Feature] Arrays. #2888

merged 51 commits into from
Oct 27, 2023

Conversation

d0cd
Copy link
Collaborator

@d0cd d0cd commented Oct 13, 2023

This PR:

  • adds support for arrays in the Leo language.
  • introduces the TypeTable, which tracks the types of expressions across the AST passes.
  • refactors tuple destructuring out of the flattening pass.

Arrays

  • Arrays must be static.
  • Arrays only support constant accesses (the index must be a constant value).
  • Arrays can be accessed by any constant integer.
  • Arrays can contain primitive data types, structs, or arrays.
  • Structs and records can contain arrays.
  • Arrays can be initialized via an array expression, e.g [a, b, c, d]
  • Arrays cannot be empty.
  • Arrays cannot be modified.

Let's look at some example code.

program test.aleo {
    transition sum_with_loop(a: [u64; 4]) -> u64 {
        let sum: u64 = 0u64;
        for i: u8 in 0u8..4u8 {
            sum += a[i];
        }
        return sum;
    }
}

This function takes in an array as input and returns the sum of its elements.
Note that array types can be declared as [<element_type>; <nonzero_number>]

@d0cd d0cd marked this pull request as ready for review October 13, 2023 20:38
@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

Merging #2888 (54566c0) into testnet3 (a5f164c) will increase coverage by 0.34%.
The diff coverage is 79.61%.

@@             Coverage Diff              @@
##           testnet3    #2888      +/-   ##
============================================
+ Coverage     78.90%   79.24%   +0.34%     
============================================
  Files           164      172       +8     
  Lines          5522     5791     +269     
  Branches       5522     5791     +269     
============================================
+ Hits           4357     4589     +232     
- Misses         1165     1202      +37     
Files Coverage Δ
compiler/ast/src/access/tuple_access.rs 100.00% <ø> (ø)
compiler/ast/src/expressions/literal.rs 79.16% <ø> (-4.17%) ⬇️
compiler/ast/src/functions/mod.rs 100.00% <100.00%> (ø)
compiler/ast/src/passes/consumer.rs 85.18% <100.00%> (+1.18%) ⬆️
compiler/ast/src/types/tuple.rs 100.00% <100.00%> (ø)
compiler/ast/src/types/type_.rs 94.44% <100.00%> (+0.32%) ⬆️
compiler/compiler/tests/compile.rs 97.14% <100.00%> (+0.08%) ⬆️
compiler/compiler/tests/execute.rs 87.75% <100.00%> (ø)
.../compiler/tests/utilities/check_unique_node_ids.rs 90.90% <100.00%> (+1.21%) ⬆️
compiler/compiler/tests/utilities/mod.rs 89.15% <100.00%> (+0.26%) ⬆️
... and 54 more

... and 9 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@acoglio acoglio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, modulo a comment I left, but I'm not super-familiar with certain parts of the code yet. I'm also happy to take another look when more documentation is added — you can just re-request a review.

@d0cd d0cd force-pushed the feat/array branch 2 times, most recently from b6851a9 to 116d83b Compare October 27, 2023 00:56
@d0cd d0cd merged commit 63b75db into testnet3 Oct 27, 2023
8 checks passed
@d0cd d0cd deleted the feat/array branch October 27, 2023 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants